Skip to content

fix(player): guard against undefined button from createPlayerButton#4152

Open
baima365-web wants to merge 1 commit into
code-charity:masterfrom
baima365-web:fix/playback-speed-button-null-check
Open

fix(player): guard against undefined button from createPlayerButton#4152
baima365-web wants to merge 1 commit into
code-charity:masterfrom
baima365-web:fix/playback-speed-button-null-check

Conversation

@baima365-web

Copy link
Copy Markdown

Problem

When YouTube's playback speed button hasn't been added to the DOM yet, createPlayerButton() returns undefined because player_left_controls or player_right_controls don't exist. Calling onclick / addEventListener on undefined throws a TypeError and breaks subsequent button initialization (repeat, screenshot, rotate, etc.).

Error: Uncaught TypeError: can't access property "addEventListener", button is undefined

This manifests as ImproveTube's extra buttons not appearing until the page is manually refreshed.

Fix

Add an early return check if (!button) return; after createPlayerButton() in both playerPlaybackSpeedButton function definitions.

Changes

  • js&css/web-accessible/www.youtube.com/player.js: Added null guard in both playerPlaybackSpeedButton function definitions (lines 701 and 1100)

When YouTube's playback speed button hasn't been added to the DOM yet,
createPlayerButton returns undefined. Calling .onclick/.addEventListener
on undefined throws TypeError and breaks subsequent button initialization.

Fix: early return if button is falsy after createPlayerButton returns.

Closes code-charity#4114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant